﻿Imports System.Data.SqlClient
Public Class clsHISTORICO
    Private mstrID_HISTORICO_RECAUDACION As String
    Private mstrID_VEHICULO As String
    Private mstrID_RUTA As String
    Private mstrID_CONDUCTOR As String
    Private mdatFECHA_HORA_INICIO As Date
    Private mdatFECHA_HORA_FIN As Date
    Private mintMINUTOS As Integer
    Private mintPASAJEROS As Integer
    Private mdblMONTO As Double
    Private mintMARCAS_DESCONTADAS As Integer
    Private mdblMONTO_MARCAS_DESCONTADAS As Double
    Private mdblMONTO_DEDUCCIONES As Double
    Private mintBLOQUEOS As Integer
    Private mdblKMS As Double
    Private mdblVUELTAS As Double
    Private mdblMONTO_MENOS_DEDUCCIONES As Double
    Private mstrID_SECTOR As String
    Private mstrID_ZONA As String
    Private mdatFECHA As Date

    Public Property ID_HISTORICO_RECAUDACION() As String
        Get
            Return mstrID_HISTORICO_RECAUDACION
        End Get
        Set(ByVal value As String)
            mstrID_HISTORICO_RECAUDACION = value
        End Set
    End Property
    Public Property ID_VEHICULO() As String
        Get
            Return mstrID_VEHICULO
        End Get
        Set(ByVal value As String)
            mstrID_VEHICULO = value
        End Set
    End Property
    Public Property ID_RUTA() As String
        Get
            Return mstrID_RUTA
        End Get
        Set(ByVal value As String)
            mstrID_RUTA = value
        End Set
    End Property
    Public Property ID_CONDUCTOR() As String
        Get
            Return mstrID_CONDUCTOR
        End Get
        Set(ByVal value As String)
            mstrID_CONDUCTOR = value
        End Set
    End Property
    Public Property FECHA_HORA_INICIO() As Date
        Get
            Return mdatFECHA_HORA_INICIO
        End Get
        Set(ByVal value As Date)
            mdatFECHA_HORA_INICIO = value
        End Set
    End Property
    Public Property FECHA_HORA_FIN() As Date
        Get
            Return mdatFECHA_HORA_FIN
        End Get
        Set(ByVal value As Date)
            mdatFECHA_HORA_FIN = value
        End Set
    End Property
    Public Property MINUTOS() As Integer
        Get
            Return mintMINUTOS
        End Get
        Set(ByVal value As Integer)
            mintMINUTOS = value
        End Set
    End Property
    Public Property PASAJEROS() As String
        Get
            Return mintPASAJEROS
        End Get
        Set(ByVal value As String)
            mintPASAJEROS = value
        End Set
    End Property
    Public Property MONTO() As Double
        Get
            Return mdblMONTO

        End Get
        Set(ByVal value As Double)
            mdblMONTO = value

        End Set
    End Property

    Public Property MARCAS_DESCONTADAS() As Integer
        Get
            Return mintMARCAS_DESCONTADAS
        End Get
        Set(ByVal value As Integer)
            mintMARCAS_DESCONTADAS = value
        End Set
    End Property
    Public Property MONTO_MARCAS_DESCONTADAS() As Double
        Get
            Return mdblMONTO_MARCAS_DESCONTADAS
        End Get
        Set(ByVal value As Double)
            mdblMONTO_MARCAS_DESCONTADAS = value
        End Set
    End Property

    Public Property MONTO_DEDUCCIONES() As Double
        Get
            Return mdblMONTO_DEDUCCIONES
        End Get
        Set(ByVal value As Double)
            mdblMONTO_DEDUCCIONES = value
        End Set
    End Property
    Public Property BLOQUEOS() As Integer
        Get
            Return mintBLOQUEOS
        End Get
        Set(ByVal value As Integer)
            mintBLOQUEOS = value
        End Set
    End Property
    Public Property KMS() As Double
        Get
            Return mdblKMS
        End Get
        Set(ByVal value As Double)
            mdblKMS = value
        End Set
    End Property
    Public Property VUELTAS() As Double
        Get
            Return mdblVUELTAS
        End Get
        Set(ByVal value As Double)
            mdblVUELTAS = value
        End Set
    End Property
    Public Property MONTO_MENOS_DEDUCCIONES() As Double
        Get
            Return mdblMONTO_MENOS_DEDUCCIONES
        End Get
        Set(ByVal value As Double)
            mdblMONTO_MENOS_DEDUCCIONES = value
        End Set
    End Property
    Public Property ID_SECTOR() As String
        Get
            Return mstrID_SECTOR
        End Get
        Set(ByVal value As String)
            mstrID_SECTOR = value
        End Set
    End Property
    Public Property ID_ZONA() As String
        Get
            Return mstrID_ZONA
        End Get
        Set(ByVal value As String)
            mstrID_ZONA = value
        End Set
    End Property
    Public Property FECHA() As Date
        Get
            Return mdatFECHA
        End Get
        Set(ByVal value As Date)
            mdatFECHA = value
        End Set
    End Property
    Public Sub New()
        mstrID_HISTORICO_RECAUDACION = ""
        mstrID_VEHICULO = ""
        mstrID_RUTA = ""
        mstrID_CONDUCTOR = ""
        mdatFECHA_HORA_INICIO = Now()
        mdatFECHA_HORA_FIN = Now()
        mintMINUTOS = 0
        mintPASAJEROS = 0
        mdblMONTO = 0
        mintMARCAS_DESCONTADAS = 0
        mdblMONTO_MARCAS_DESCONTADAS = 0
        mdblMONTO_DEDUCCIONES = 0
        mintBLOQUEOS = 0
        mdblKMS = 0
        mdblVUELTAS = 0
        mdblMONTO_MENOS_DEDUCCIONES = 0
        mstrID_SECTOR = ""
        mstrID_ZONA = ""
        mdatFECHA = Now()
    End Sub
    Public Sub Insertar()
        Dim sql As String = "Insert Into HISTORICO_RECAUDACION (" & _
                            "ID_HISTORICO_RECAUDACION," & _
                            "ID_VEHICULO," & _
                            "ID_RUTA," & _
                            "ID_CONDUCTOR," & _
                            "FECHA_HORA_INICIO," & _
                            "FECHA_HORA_FIN," & _
                            "MINUTOS," & _
                            "PASAJEROS," & _
                            "MONTO," & _
                            "MARCAS_DESCONTADAS," & _
                            "MONTO_MARCAS_DESCONTADAS," & _
                            "MONTO_DEDUCCIONES," & _
                            "BLOQUEOS," & _
                            "KMS," & _
                            "VUELTAS," & _
                            "MONTO_MENOS_DEDUCCIONES," & _
                            "ID_SECTOR," & _
                            "ID_ZONA," & _
                            "FECHA)" & _
                            "VALUES (" & _
                            "SUBSTRING(@ID_HISTORICO_RECAUDACION,1,100)," & _
                            "SUBSTRING(@ID_VEHICULO,1,100)," & _
                            "SUBSTRING(@ID_RUTA,1,100)," & _
                            "SUBSTRING(@ID_CONDUCTOR,1,100)," & _
                            "@FECHA_HORA_INICIO," & _
                            "@FECHA_HORA_FIN," & _
                            "@MINUTOS," & _
                            "@PASAJEROS," & _
                            "@MONTO," & _
                            "@MARCAS_DESCONTADAS," & _
                            "@MONTO_MARCAS_DESCONTADAS," & _
                            "@MONTO_DEDUCCIONES," & _
                            "@BLOQUEOS," & _
                            "@KMS," & _
                            "@VUELTAS," & _
                            "@MONTO_MENOS_DEDUCCIONES," & _
                            "SUBSTRING(@ID_SECTOR,1,100)," & _
                            "SUBSTRING(@ID_ZONA,1,100)," & _
                            "@FECHA)"

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = OptocontrolConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("ID_HISTORICO_RECAUDACION", mstrID_HISTORICO_RECAUDACION)
        Command.Parameters.AddWithValue("ID_VEHICULO", mstrID_VEHICULO)
        Command.Parameters.AddWithValue("ID_RUTA", mstrID_RUTA)
        Command.Parameters.AddWithValue("ID_CONDUCTOR", mstrID_CONDUCTOR)
        Command.Parameters.AddWithValue("FECHA_HORA_INICIO", mdatFECHA_HORA_INICIO)
        Command.Parameters.AddWithValue("FECHA_HORA_FIN", mdatFECHA_HORA_FIN)
        Command.Parameters.AddWithValue("MINUTOS", mintMINUTOS)
        Command.Parameters.AddWithValue("PASAJEROS", mintPASAJEROS)
        Command.Parameters.AddWithValue("MONTO", mdblMONTO)
        Command.Parameters.AddWithValue("MARCAS_DESCONTADAS", mintMARCAS_DESCONTADAS)
        Command.Parameters.AddWithValue("MONTO_MARCAS_DESCONTADAS", mdblMONTO_MARCAS_DESCONTADAS)
        Command.Parameters.AddWithValue("MONTO_DEDUCCIONES", mdblMONTO_DEDUCCIONES)
        Command.Parameters.AddWithValue("BLOQUEOS", mintBLOQUEOS)
        Command.Parameters.AddWithValue("KMS", mdblKMS)
        Command.Parameters.AddWithValue("VUELTAS", mdblVUELTAS)
        Command.Parameters.AddWithValue("MONTO_MENOS_DEDUCCIONES", mdblMONTO_MENOS_DEDUCCIONES)
        Command.Parameters.AddWithValue("ID_SECTOR", mstrID_SECTOR)
        Command.Parameters.AddWithValue("ID_ZONA", mstrID_ZONA)
        Command.Parameters.AddWithValue("FECHA", mdatFECHA)

        cnConn.Open()
        Dim RowsAffected As Integer
        Try
            RowsAffected = Command.ExecuteNonQuery
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Aviso")
        End Try

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar el registro de analisis", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
End Class
